#define  _IO_GLOBAL_
#include "config.h"


void BackDect(void)
{
	static u32 last;
	static u8 dat[3] = {0};
	static u8 i = 0;
	if (GetTickCount()-last>10*T_1MS)
	{
		last = GetTickCount();
		dat[i] = STM_BACK_STATUS;
		i = (i+1)%3;
		if ((dat[0] == dat[1]) && (dat[1]==dat[2]))
		{
            IOInfo.innerIO360EN = dat[0];
		}
	}
}

void LedKeepAlive(void)
{
	static u32 last;
	static BOOL onoff;
	u32 delaytime;
	if( GetTickCount() - ACCInfo.accOffDelayTime >= T_1S*2)
	{
		delaytime = T_1MS*2000;
	}
	else
	{
		delaytime = T_1MS*500;
	}

	if (gCarInfo.BatteryVoltage<85)
	{
		delaytime = T_1MS*500;
	}
	
	if(GetTickCount()-last>delaytime)
	{
		onoff = !onoff;
		if (onoff)
		{
			LED_STM32_ON;
		}else
		{
			LED_STM32_OFF;
		}
		last = GetTickCount();
	}
}


void IOFreeIdleProc(void)
{
	IOInfo.I2CDebugConnect = I2C_EN_STATUS;
	//BackDect();
	//IOTestSpkSW();

	//testSwitchDRGB_CVBS();
	LedKeepAlive();
}

void IOInit(void)
{
	memset(&IOInfo,0,sizeof(IO_INFO));	
	I2C_EN_INIT;
	LVDS_SW_INIT;
	LVDS_CAR;

	LED_STM32_INIT;
	LED_STM32_ON;
	PWR_SELF_ON;

	ARM_RESET_HIGH;
    
    TW_RST_HIGH;
    
	BATTERY_DECT_INIT;

    STM_FINE12V_DI;

    STM_MUTE_HIGH;
    STM_MUTE_LOW;
	
	NAV_AUDIO_OFF;
	STM_BACK_DET_INIT;
}

